﻿Public Class LoginForm1
    Public Function Crypt(ByVal Text As String) As String
        Dim strTempChar As String
        For i = 1 To Len(Text)
            If Asc(Mid$(Text, i, 1)) < 128 Then
                strTempChar = Asc(Mid$(Text, i, 1)) + 128
            ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
                strTempChar = Asc(Mid$(Text, i, 1)) - 128
            End If
            Mid$(Text, i, 1) = Chr(strTempChar)
        Next i
        Crypt = Text
    End Function

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If USUARIOTextBox.Text = "" Or SENHATextBox.Text = "" Then
            MsgBox("FAVOR INFORMAR LOGIN/SENHA")
        Else
            SENHATextBox.Text = Crypt(SENHATextBox.Text)
                LOGINTableAdapter.FillByUSUARIOSENHA(LOGINDataSet.LOGIN, USUARIOTextBox.Text, SENHATextBox.Text)
            End If
        If LOGINDataSet.Tables(0).Rows.Count > 0 Then
            If Date.Now.Day = 14 And Date.Now.Month = 11 Then
                MsgBox("PARABÉNS CLÁUDIA")
            ElseIf Date.Now.Day = 3 And Date.Now.Month = 2 Then
                MsgBox("PARABÉNS CRISTIANO")
            ElseIf Date.Now.Day = 13 And Date.Now.Month = 2 Then
                MsgBox("PARABÉNS KELLY")
            ElseIf Date.Now.Day = 5 And Date.Now.Month = 6 Then
                MsgBox("PARABÉNS ADELAINE")
            ElseIf Date.Now.Day = 6 And Date.Now.Month = 7 Then
                MsgBox("PARABÉNS DANIELA")
            ElseIf Date.Now.Day = 6 And Date.Now.Month = 11 Then
                MsgBox("PARABÉNS JANAINA")
            ElseIf Date.Now.Day = 28 And Date.Now.Month = 9 Then
                MsgBox("PARABÉNS LUIZ")
            ElseIf Date.Now.Day = 21 And Date.Now.Month = 9 Then
                MsgBox("PARABÉNS MAX")
            ElseIf Date.Now.Day = 22 And Date.Now.Month = 12 Then
                MsgBox("PARABÉNS FABIANE")
            End If
            If STATUSLabel1.Text = "LOGADO" Then
                MsgBox("USUÁRIO JÁ LOGADO")
            Else
                Try
                    STATUSLabel1.Text = "LOGADO"
                    LOGINBindingSource.EndEdit()
                    Me.TableAdapterManager.UpdateAll(Me.LOGINDataSet)
                Catch ex As Exception
                    MsgBox("ERRO AO LOGAR O USUÁRIO")
                End Try
                GroupBox1.Visible = True
                Me.Hide()
                Principal.Show()
            End If
        Else
            MsgBox("USUÁRIO OU SENHA INVÁLIDOS FAVOR VERIFICAR")
        End If
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub
    Private Sub LoginForm1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            STATUSLabel1.Text = "DESLOGADO"
            LOGINBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.LOGINDataSet)
        Catch ex As Exception
            MsgBox("ERRO AO DESLOGAR O USUÁRIO FAVOR ENTRAR EM CONTATO COM O ADMINISTRADOR" & ex.ToString)
            Me.Close()
        End Try
    End Sub
End Class
